package net.zjitc.android2019.ch5broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

/**
 * 广播接收者：接收系统或APP的广播
 * onReceive（）方法：一旦接收到已订阅的广播，自动调用该方法
 *    1、获取拨打的电话号码
 *    2、从sp中获取要拦截的号码
 *    3、判断若是要拦截的号码：
 *        清除外拨电话
 *
 */
public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
//        throw new UnsupportedOperationException("Not yet implemented");

        /* 获取拨打的号码*/
        String number=getResultData();
        SharedPreferences sp=context.getSharedPreferences("phone",Context.MODE_PRIVATE);
        String phone=sp.getString("phone",null);
        if(number.equals(phone)){
            /* 设置拨打号码*/
            setResultData(null);
        }

    }
}
